<?php
declare (strict_types = 1);

namespace app\admin\service\system;

use app\admin\logic\system\Message as MessageLogic;
use app\common\service\BaseService;
use eduline\admin\page\PageList;

class Message extends BaseService
{
    /**
     * 后台系统消息列表
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-06-23
     */
    public function index()
    {
        $datas = app(MessageLogic::class)->getList();
        // 设置表单
        $list        = app(PageList::class);
        $list->datas = $datas;

        return $list->send();
    }

    /**
     * 未读消息数量
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-08-11
     * @return   [type]                         [description]
     */
    public function noReadCount()
    {
        $count = app(MessageLogic::class)->getNoReadCount(request()->admin_user_id);

        return $this->parseToData(['no_read_count' => $count], 1);
    }

    /**
     * 设置消息已读
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-08-11
     * @param    int                            $message_id [description]
     * @return   [type]                                     [description]
     */
    public function read(int $message_id)
    {
        $count = app(MessageLogic::class)->setRead($message_id, request()->admin_user_id);

        return $this->parseToData(['no_read_count' => $count], 1, '设置成功');
    }

    /**
     * 设置消息全部已读
     * Author: 亓官雨树 <lucky.max@foxmail.com>
     * Date: 22/02/08
     *
     * @return mixed
     */
    public function readAll()
    {
        /** @var MessageLogic $msgLogic */
        $msgLogic = app(MessageLogic::class);
        $msgLogic->setReadAll( request()->admin_user_id);

        return $this->parseToData([], 1, '设置成功');
    }
}
